#! /usr/bin/python3

import dns.resolver
import os


iplist = []		# 定义域名 IP列表变量
appdomain = "www.taobao.com"		# 定义查询域名

def get_iplist(domain = ""):		# 域名解析函数，解析成功将追加到 iplist
	try:
		A = dns.resolver.query(domain, 'A')		# 解析A记录类型
	except Exception as err:
		print ("dns resolver error:" + str(err))
		return
	for i in A.response.answer:
		#print (i)
		for j in i.items:
			#print (j)
			iplist.append(j)		# 追加 iplist
	return True

# 根据解析到的ip地址请求抓取页面（未完成）
def checkip(ip):
	checkurl = ip + ":80"
	print (checkurl)

if get_iplist(appdomain) and len(iplist) > 0:		# 条件：域名解析正确且至少返回一个IP
	#print (iplist)
	for ip in iplist:
		#print (ip)
		ip = str(ip)
		checkip(ip)